package com.ssy.lingxi.system.config.interceptor;

import com.ssy.lingxi.system.service.ITokenAndAuthService;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器
 */
@Component
public class LoginInterceptor   implements HandlerInterceptor {

    @Resource
    ITokenAndAuthService tokenAndAuthService;

    /**
    * 权限校验再请求方法前处理
    */
    @Override
    public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("token");
        return  tokenAndAuthService.authToken(token,request.getRequestURI());
    }

    @Override
    public void postHandle(HttpServletRequest request,
                           HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    }

    @Override
    public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
    }

}
